package com.ycsd.invest.order.business.printplugin;

import kd.bos.print.core.data.DataRowSet;
import kd.bos.print.core.data.datasource.PrtDataSource;
import kd.bos.print.core.data.field.TextField;
import kd.bos.print.core.plugin.AbstractPrintPlugin;
import kd.bos.print.core.plugin.event.AfterLoadDataEvent;
import kd.bos.print.core.plugin.event.BeforeExportEvent;
import kd.bos.print.core.plugin.event.BeforeLoadDataEvent;

import java.util.List;
import java.util.Map;

/**
 * @Descrіption:打印插件
 * @Author: yn
 * @Date: 2025/6/23 17:12
 */
public class TestPrintPlugin extends AbstractPrintPlugin {

    /**
     * @Author yn
     * @Description 引擎加载数据前触发
     * @Date 2025/6/23
     * @Param [evt]
     * @return void
     **/
    @Override
    public void beforeLoadData(BeforeLoadDataEvent evt) {
        PrtDataSource dataSource = evt.getDataSource();
        List<DataRowSet> dataRowSets = evt.getDataRowSets();
        boolean cancleLoadData = evt.isCancleLoadData();
        boolean preview = this.isPreview();
        //实现一个列表插件，在beforeDoOperation事件中放入key=extParam的参数，具体参考
        //在打印插件中就可以使用this.getExtParam()获取到传进来的参数
        Map<String, Object> extParam = this.getExtParam();
    }

    @Override
    public void afterLoadData(AfterLoadDataEvent evt) {
        PrtDataSource dataSource = evt.getDataSource();
        //获取打印数据
        List<DataRowSet> dataRowSets = evt.getDataRowSets();

        for (DataRowSet dataRowSet : dataRowSets) {
            //获取多基础资料数据
            TextField field = (TextField)dataRowSet.getField("languages");
            String peopleStr = field.toString();
            String[] split = peopleStr.split(",");

            //设置语种个数
            field.setValue(split.length + "种语言");

        }

    }

    /**
     * @Author yn
     * @Description 引擎开始输出事件
     * @Date 2025/6/23
     * @Param [evt]
     * @return void
     **/
    @Override
    public void beforeExport(BeforeExportEvent evt) {
        String fileTplName = evt.getFileTplName();
        boolean preview = this.isPreview();
    }
}
